//
//  Array+ExtensionTests.swift
//  TDDStudySwift
//
//  Created by baidu on 6/29/16.
//  Copyright © 2016 caoyuan. All rights reserved.
//

import XCTest

class Array_ExtensionTests: XCTestCase {
    var array = [Int]()
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
        self.array = [0,1,2,3,4,5]
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
        self.array = []
    }

    func testPop() -> Void {
        let b = self.array.pyPop()
        XCTAssertEqual(b, 5, "😄👉pop shoud be 5👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4], "😄👉self.array shoud be [0,1,2,3,4]👈😄")
    }
    
    func testPop2() -> Void {
        let b = self.array.pyPop(index:0)
        XCTAssertEqual(b, 0, "😄👉pop shoud be 5👈😄")
        XCTAssertEqual(self.array, [1,2,3,4,5], "😄👉self.array shoud be [1,2,3,4,5]👈😄")
    }
    
    func testPop3() -> Void {
        let b = self.array.pyPop(index:10000)
        XCTAssertEqual(b, nil, "😄👉pop shoud be nil👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
    }
    
    func testPop4() -> Void {
        let b = self.array.pyPop(index:-1)
        XCTAssertEqual(b, nil, "😄👉pop shoud be nil👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
    }
    
    func testRange() -> Void {
        let b = self.array[1..<3]
        XCTAssertEqual(b, [1,2], "😄👉pop shoud be [1,2]👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
    }

    func testRange2() -> Void {
        let b = self.array[0..<self.array.count]

        XCTAssertEqual(b, [0,1,2,3,4,5], "😄👉pop shoud be [1,2]👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
    }

    func testFind() -> Void {
        let b = self.array.pyFind(object:3)
        XCTAssertEqual(b, 3, "😄👉b shoud be 3👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
        
    }
    
    func testFind2() -> Void {
        let b = self.array.pyFind(object:666)
        XCTAssertEqual(b, -1, "😄👉b shoud be -1👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5], "😄👉self.array shoud be [0,1,2,3,4,5]👈😄")
    }
    
    func testInsert() -> Void {
        self.array.pyInsert(index: 0, object: 666)
        print("😄👉\(self.array)👈😄")
        XCTAssertEqual(self.array, [666,0,1,2,3,4,5], "😄👉self.array shoud be [666,0,1,2,3,4,5]👈😄")
    }
    
    func testInsert1() -> Void {
        self.array.pyInsert(index: 3, object: 666)
        print("😄👉\(self.array)👈😄")
        XCTAssertEqual(self.array, [0,1,2,666,3,4,5], "😄👉self.array shoud be [0,1,2,666,3,4,5]👈😄")
    }
    
    func testInsert2() -> Void {
        self.array.pyInsert(index: 99, object: 666)
        print("😄👉\(self.array)👈😄")
        XCTAssertEqual(self.array, [0,1,2,3,4,5,666], "😄👉self.array shoud be [0,1,2,3,4,5,666]👈😄")
    }
    
    func testForEach() -> Void {
        var tmp = [0,1,2,3,4,"5"]
        let tmp2 = [0,1,2,3,4,"5"]
        tmp.forEach { (index, value) in
            print("😄👉\(index):\(value)👈😄")
            XCTAssertEqual(tmp2[index], value)
            if index == 3 {
                tmp[index] = "2222"
            }
        }
        print("😄👉\(tmp)👈😄")
        XCTAssertEqual(tmp, [0,1,2,"2222",4,"5"])
    }
    
    
    
}
